import scipdf
import fitz  # PyMuPDF

def en_extract_text(file_path: str):
    article_dict = scipdf.parse_pdf_to_dict(file_path)
    temp = []

    temp.append("文章摘要内容：" + " ".join(str(article_dict['abstract']).split(" ")[:1600]))
    i = 1
    for line in article_dict['sections']:
        if len(line["text"]) > 20:
            temp.append("文章正文第" + str(i) + "段：" + " ".join(line["text"].split(" ")[:1600]))

    return temp

def extract_text_from_pdf(pdf_path):
    text = ""
    pdf_document = fitz.open(pdf_path)
    print(pdf_path,pdf_document.page_count)
    for page_number in range(pdf_document.page_count):
        page = pdf_document.load_page(page_number)
        text += page.get_text()

    pdf_document.close()
    if len(text.split("\n \n")) == 1:
        return text.split("\n\n")
    else:
        return text.split("\n \n")